package com.cskaoyan.order.biz.handler;

import com.cskaoyan.order.biz.context.CreateOrderContext;
import com.cskaoyan.order.biz.context.TransHandlerContext;
import com.cskaoyan.order.mq.producer.DelayOrderCancelProducer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Description: 利用mq发送延迟取消订单消息
 **/
@Component
@Slf4j
public class SendMessageHandler extends AbstractTransHandler {

	@Autowired
	DelayOrderCancelProducer delayOrderCancelProducer;

	@Override
	public boolean isAsync() {
		return true;
	}

	@Override
	public boolean handle(TransHandlerContext context) {

		// 发送延迟消息即可

		// 调用一个方法实现延迟消息的发送

		CreateOrderContext createOrderContext= (CreateOrderContext) context;
		//获取订单id
		String orderId = createOrderContext.getOrderId();
		delayOrderCancelProducer.sendDelayOrderMessage(orderId);
		return true;
	}
}